function [positions, fps] = tracker(params)

% [positions, fps] = color_tracker(params)

% parameters
padding = params.padding;
output_sigma_factor = params.output_sigma_factor;
sigma = params.sigma;
lambda = params.lambda;
learning_rate = params.learning_rate;

video_path = params.video_path;
img_files = params.img_files;
pos = floor(params.init_pos);
target_sz = floor(params.wsize);

visualization = params.visualization;

num_frames = numel(img_files);

% load the normalized Color Name matrix
temp = load('w2crs');
w2c = temp.w2crs;

% window size, taking padding into account
sz_trans = floor(target_sz * (1 + padding));
sz_scale = floor(target_sz);

% desired output (gaussian shaped), bandwidth proportional to target size
output_sigma = sqrt(prod(target_sz)) * output_sigma_factor / cell_size;
yf_trans = fft2(gaussian_shaped_labels(output_sigma, floor(sz_trans / cell_size)));

output_sigma = sqrt(prod(target_sz)) * output_sigma_factor / cell_size;
yf_trans = fft2(gaussian_shaped_labels(output_sigma, floor(sz_scale / cell_size)));

% store pre-computed cosine window
cos_window = single(hann(sz(1)) * hann(sz(2))');

% to calculate precision
positions = zeros(numel(img_files), 4);

% to calculate fps
time = 0;

for frame = 1:num_frames,
    % load image
    im = imread([video_path img_files{frame}]);
    
    %training
    if frame==1
        patch = get_subwindow(im, pos, sz_trans);
        
    else
    end
    
    %visualization
    if visualization == 1
        rect_position = [pos([2,1]) - target_sz([2,1])/2, target_sz([2,1])];
        if frame == 1,  %first frame, create GUI
            figure('Name',['Tracker - ' video_path]);
            im_handle = imshow(uint8(im), 'Border','tight', 'InitialMag', 100 + 100 * (length(im) < 500));
            rect_handle = rectangle('Position',rect_position, 'EdgeColor','g');
            text_handle = text(10, 10, int2str(frame));
            set(text_handle, 'color', [0 1 1]);
        else
            try  %subsequent frames, update GUI
                set(im_handle, 'CData', im)
                set(rect_handle, 'Position', rect_position)
                set(text_handle, 'string', int2str(frame));
            catch
                return
            end
        end
        
        drawnow
%         pause
    end
end

fps = num_frames/time;
